﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;



public partial class controls_ProductDetails : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

        int productID = (int.Parse(Request["id"].ToString()));
 

        AwinDotNet.Product p = AwinDotNet.AwinAPI.Products.GetProduct(productID);

        Page.Title = p.Name;

        lblTitle.Text  = p.Name;
        lblDescription.Text = FormatDescription(p.Description);
        hypProdImgLink.NavigateUrl = p.DeepLink;
        imgProduct.ImageUrl = p.ImageURL;
        lblPrice.Text = string.Format("{0:£0.00}", p.Price);

        lblMerchantLink.Text  = MerchantLink(p.ID);

        lblBrand.Text = p.Brand;
        
        
    }


    public string MerchantLink(object productID)
    {
        string hyp = @"<a href=""{0}"">{1}</a>";
        int id = int.Parse(productID.ToString());

        AwinDotNet.Product p = AwinDotNet.AwinAPI.Products.GetProduct(id);
        if (p != null)
        {
            AwinDotNet.Merchant m = AwinDotNet.AwinAPI.Merchants[p.MerchantID];

            hyp = string.Format(hyp, p.DeepLink, m.Name);

        }
        return hyp;
    }




    private string FormatDescription(string desc)
    {

        if (desc != null)
        {
            desc = desc.Replace(".", ".<br /><br />");
        }

        return desc;
    }




    public override void RenderControl(HtmlTextWriter writer)
    {
        
        
        
        
        
        
        base.RenderControl(writer);
    }

}
